package cn.wolfcode.mq._01_hello;

import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {

    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    @RequestMapping("/sendMsg")
    public String sendMsg(String message){
        SendResult sendResult = rocketMQTemplate.syncSend("01_hello", message);
        System.out.println(sendResult.getMsgId());
        System.out.println(sendResult.getSendStatus());
        return "success";
    }

    @RequestMapping("/sendDelayMsg")
    public String sendDelayMsg(String msg){
        MessageBuilder<String> messageBuilder = MessageBuilder.withPayload(msg);
        Message<String> message = messageBuilder.build();
        rocketMQTemplate.syncSend("01_hello",message,5000,3);
        return "success";
    }
}
